
package com.sausageking.auth;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sausageking.shared.Consumer;

@SuppressWarnings("serial")
public class MyOffersServlet extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {

    String email = "";
    HttpSession session = req.getSession();
    Consumer user = (Consumer) session.getAttribute("consumer");
    if (user != null) {
      email = user.getEmail();
    }

    resp.setContentType("text/plain");
    if (email.isEmpty()) {
      resp.getWriter().println("Wrong password or the user does not exist. ");
      resp.getWriter().println("Please login here.");
    } else {
      resp.getWriter().println(
          "The user email/password is valid: " + user.getEmail());
      String destination = "/myoffers.html";
      resp.sendRedirect(resp.encodeRedirectURL(destination));
    }
  }
}
